var select2;
var toolbar1 =

    '<div id="toolbar" class="btn-group">\n' +
    '        <button id="btn_delete" type="button" class="btn btn-danger btn-xs" onclick="deletes()"><i class="fa fa-trash-o"></i>删除</button>' +
    ' </div>'
$(function () {
    select2 = $('.select2').select2()
    var columns = [
        {
            field: 'ck',
            checkbox: true
        },
        {
            field: 'loginName',
            title: '用户名'
        },
        {
            field: 'gender',
            title: '性别',
            formatter: function (value, row, index) {
                if (value == 0) {
                    return '男'
                }
                if (value == 1) {
                    return '女'
                }
                return "未知"
            }
        },
        {
            field: 'avatar',
            title: '头像',
            formatter: function (value) {
                return '<image style="height: 100px;width: 100px" src=' + value + '></image>'
            }
        },
        {
            field: 'updateDate',
            title: '登录时间',
        },
        {
            field: '注册时间',
            title: '创建时间',
        },
        {
            field: 'id',
            title: '操作',
            formatter: function (value, row, index) {
                return '<button type="button" class="btn btn-danger  btn-xs" onclick="deletes(\'' + value + '\')" style="margin-left: 10px;"><i class="fa fa-trash-o"></i> 删除</button>';
            }
        }
    ]
    createBootstrapTable($("#table"), '/shop/wxUser/findPage', columns, true, toolbar1, 'server')
})

var add_form;
var loading;


function deletes(id) {
    var ids = [];
    if (id != undefined) {
        ids.push(id)
    } else {
        $.each($('tbody input:checkbox:checked'), function () {
            ids.push($(this).parents('tr').data('uniqueid'));
        });
    }
    if (ids.length < 1) {
        layer.msg("最少请选择一条数据！")
        return;
    }
    var data = {
        ids: ids.toString()
    }

    layer.confirm('确定删除吗？', {
        title: '提示', btn: ['取消', '确定'] //按钮
    }, function () {
        layer.close(layer.index)
    }, function () {
        request('/shop/wxUser/delete', 1, data, function (res) {
            if (res.code == 0) {
                layer.msg("删除成功", {time: 1000}, function () {
                    onLoads($("#href").val())
                })
            } else {
                layer.msg(res.msg, {time: 1000})
            }
        }, function (error) {
            layer.msg("系统异常！")
        })
    });
}

function resetForm() {
    $("#searchForm")[0].reset();
    $("#table").bootstrapTable('refresh');
}

// 查询
function searchForm(tableId, url, FormId) {
    var data = serializeObject("searchForm");
    var opt = {
        url: '/shop/wxUser/findPage',
        silent: true,
        query: data
    };
    $("#table").bootstrapTable('refresh', opt);
}


